home *** CD-ROM | disk | FTP | other *** search
- Path: erich.triumf.ca!bennett
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c
- Subject: Re: Correct input from user.
- Date: 30 Mar 1996 15:16 PST
- Organization: TRIUMF: Tri-University Meson Facility
- Distribution: world
- Message-ID: <30MAR199615162182@erich.triumf.ca>
- References: <4jjfur$5fu@dfw-ixnews6.ix.netcom.com>
- NNTP-Posting-Host: erich.triumf.ca
- News-Software: VAX/VMS VNEWS 1.50
-
- In article <4jjfur$5fu@dfw-ixnews6.ix.netcom.com>, egurevit@soleil.acomp.usf.edu (Eric Gurevitz) writes...
- >I am writing for school. The program is to take the interest rate,
- >number of years, and principal amount and return the monthly payment.
- >For each of the things I ask the user I am using a scanf and storing
- >it as a float. I would like to make a loop so that is the user types a
- >lettter when asked for a number it prints an error message and tell
- >them to try again. I am using GCC and writing it in C. Thnaks for the
- >help.
-
- Use fgets() to get the input, then convert it (if possible) with sscanf().
- Check the return value of sscanf() to see if it was successful, or/and check
- the buffer for appropriate chars before trying the conversion. It is generally
- a bad idea to use scanf() for direct user input.
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
- or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
-
-